import * as apis from 'services/products'
import * as types from '../mutation-types'

const state = {
  list: [],
  total: 0,
}

const actions = {
  async getProducts({ commit }, params) {
    const info = await apis.getProducts(params)
    commit(types.GET_PRODUCTS_SUCCESS, info)
  },
}

const mutations = {
  [types.GET_PRODUCTS_SUCCESS](state, info) {
    state.list = info.data
    state.total = info.total
  },
}

export default {
  state,
  actions,
  mutations,
}
